package com.jyy.prefabricated.listener;

import net.polyv.vod.v1.config.VodGlobalConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;


/**
 * spring容器初始化完成事件
 */
@Component
public class ApplicationContextListener implements ApplicationListener<ContextRefreshedEvent> {

    private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationContextListener.class);
    @Value("${polyv.userId}")
    private String userId;

    @Value("${polyv.secretKey}")
    private String secretKey;
    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        // root application context
        /*if(contextRefreshedEvent.getApplicationContext().getParent() == null) {
            VodGlobalConfig.init(userId, secretKey);
            LOGGER.info("保利威配置初始化结束...........");
        }*/
        Integer timeOut = 20000;  //HTTP CLIENT 连接池超时时间
        Integer maxClientNum = 100;  //HTTP CLIENT 最大连接数
        VodGlobalConfig.init(userId, secretKey, timeOut, maxClientNum);
        LOGGER.info("保利威配置初始化结束...........");
    }

}
